package com.hl.card.modular.packBack.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.hl.card.common.persistence.dao.UserMapper;
import com.hl.card.common.persistence.model.DistinguishIdCard;
import com.hl.card.common.persistence.model.User;
import com.hl.card.common.util.DateUtils;
import com.hl.card.modular.packBack.service.DateUpdateService;

@Service
public class DateUpdateServiceImpl implements DateUpdateService{
	private static String COLLECTION_NAME = "IdCardInfo";
	@Autowired
	private MongoTemplate mongoTemplate;
	@Autowired
	private UserMapper userMapper;
	
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
	public void updateDate() {
		Query query = Query.query(Criteria.where("auth").is("3"));
		List<DistinguishIdCard> list=mongoTemplate.find(query, DistinguishIdCard.class, COLLECTION_NAME);
		System.out.println("开始执行-------------------------->");
		for(DistinguishIdCard distinguishIdCard:list)
		{
			User user=new User();
			user.setIsauth(0);
			user.setUserId(distinguishIdCard.getUser_id());
			user.setDetailinfo(JSON.toJSONString(distinguishIdCard));
			userMapper.updateUserInfo(user);
			System.out.println("更新:"+user.getUserId()+"信息！");
		}
		
		System.out.println("结束执行-------------------------->");
	}

}
